﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using MySql.Data.MySqlClient;

namespace 旅游管理员终端
{
    public partial class Diagram : Form
    {
        public MySqlConnection conn;
        private String connectStr;
        MySqlDataAdapter mySqlDataAdapter;
        DataSet dataSet;
        public Diagram(string str)
        {
            InitializeComponent();
            connectStr = str;
        }
        public void Database_connection()
        {
            //打开数据库连接
            try
            {
                conn = new MySqlConnection(connectStr);
                conn.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        private void Diagram_Load(object sender, EventArgs e)
        {
            //页面加载函数，打开页面即执行数据库连接
            Database_connection();
            Chart_Load_Option(conn);
        }

        public void Chart_Load_Option(MySqlConnection conn)
        {
            MySqlCommand cmd = new MySqlCommand("select * from city_tbl", conn);
            mySqlDataAdapter = new MySqlDataAdapter(cmd);
            dataSet = new DataSet();
            mySqlDataAdapter.Fill(dataSet, "city_tbl");
            Chart.DataSource = dataSet.Tables["city_tbl"];
            Chart.Series[0].XValueMember = "name";
            Chart.Series[0].YValueMembers = "hot";
            Chart.ChartAreas[0].AxisX.Title = "城市";
            Chart.ChartAreas[0].AxisY.Title = "热度";
            Chart.ChartAreas[0].AxisY.Minimum = 0;
            Chart.ChartAreas[0].AxisY.Maximum = 120;
            Chart.Series[0].ChartType = SeriesChartType.Line;
            Chart.Series[0].LegendText = "热度值";
            Chart.Series[0].IsValueShownAsLabel = true;
            Chart.Series[0].BorderWidth = 2;
            Chart.ChartAreas[0].AxisX.Interval = 1;
            Chart.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
            Chart.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
            
        }






    }
}
